<?php
/*
=====================================================
 Generic Toolbox - by Carl Wells
-----------------------------------------------------
-----------------------------------------------------
 Copyright (c) 2009 Carl Wells
=====================================================
 THIS IS COPYRIGHTED SOFTWARE
 PLEASE READ THE LICENSE AGREEMENT
=====================================================
 File: system/index.php
-----------------------------------------------------
 Purpose: This file is the base for the control panel.
 All admin functions are run from this view.
=====================================================
*/

// ----------------------------------------------
//  include CONFIG file
// ----------------------------------------------    
 	require_once 'config/config.php';
 
// ----------------------------------------------
//  include SESSION file
// ----------------------------------------------    
 	require_once 'core/sessions.class.php';
	
// ----------------------------------------------
//  Instantiate MAIN CORE class
// ----------------------------------------------    
 	require_once 'core/main.class.php';
 	$MAIN = new main();  
 	
 	$SESS= new Session(); 
 	
 	require_once 'users/userAccess.class.php';
 	$userAccess = new UserAccess();
 	
// 	$userAccess->isLoggedIn(10);
 	
 	
    
// ----------------------------------------------
//  Instantiate generic display class
// ----------------------------------------------    
 	require_once 'display/genericdisplay.class.php';
    $GENDISPLAY = new Genericdisplay();
    echo ($GENDISPLAY->html_header('admin_style.css'));
    
    // OPEN THE BODY FOR OUTPUT
	$GENDISPLAY->body_open();
	
// ----------------------------------------------
//  Instantiate admin display class
// ----------------------------------------------    
	require_once 'display/groupdisplay.class.php';
	$GROUPDISPLAY = new Groupdisplay();
	require_once 'display/admindisplay.class.php';
	$ADMINDISPLAY = new Admindisplay();
	require_once 'db/dbGroup.class.php';
	$USERDB = new DbGroup();
    
    ?>
    
    <div id="maincontainer">

<?php echo ($GROUPDISPLAY->display_header()); ?>
<div id="contentwrapper">
<div id="contentcolumn">
<div class="innertube"><h3>Groups</h3>
<?php
require_once ("display/navdisplay.class.php");
$NAVDISPLAY = new Navdisplay();
$NAVDISPLAY->displayPromosNav("groups.php?");
?>

<script language="javascript" type="text/javascript">
<!-- 

//Browser Support Code
function getUsers(id){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//var ajaxDisplay = document.getElementById('groupusersingroup');
			var responseArray = ajaxRequest.responseText.split('[brk]');
			document.getElementById('groupusers').innerHTML = responseArray[0];
			document.getElementById('usersnotingroup').innerHTML = responseArray[1];
		}
	}
	var categoryId = id;
	
	var queryString = "?sector=<?php echo $_GET['sector']; ?>&categoryId=" + id;
	ajaxRequest.open("GET", "ajax/getgroups.php" + queryString, true);
	ajaxRequest.send(null); 
}

function moveusergroup(id, thedirection, groupId){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	
	test = groupId;
	var queryString = "?sector=<?php echo $_GET['sector']; ?>&username=" + id + "&direction=" + thedirection + "&groupId=" + groupId;	
	ajaxRequest.open("GET", "ajax/moveusergroup.php" + queryString, true);
	ajaxRequest.foo = "test";
	ajaxRequest.onreadystatechange = function() {
	
    	if(ajaxRequest.readyState == 4){
				getUsers(test);
			}
		if(ajaxRequest.readyState < 4){
				document.body.style.cursor = "progress";
			}else{
				document.body.style.cursor = "default";
			}
			
			
		
	}
	ajaxRequest.send(null);

	
	//ajaxRequest.send(null);
	
}

function sndReq(action, formelement) {
gElem = formelement;
http.open('get', action);
http.onreadystatechange = handleResponse(formelement);
http.send(null);
}

function handleResponse(divVariable) {
if(http.readyState == 4){
var oElem = document.getElementById(gElem);
var replaceText = oElem.value;
oElem.innerHTML = replaceText;
}
}

//-->
</script>


<form>
<input type="hidden" id="sector" name="sector" value="<?php echo $_GET['sector']; ?>">
<!-- START OF GROUP BLOCK-->
<div id="groupblock">
<div id="groupmanagement">

<a href="#" onclick="viewNewGroup()">New Group?</a>

<?php
echo ($GROUPDISPLAY->displayGroupSelect($_GET['sector']));
?>


<label id="newGroup">Name of Group<input type="text" id="nameOfGroup" name="nameOfGroup" size="20"><button type="submit" id="addGroup" value="">Add Group</button></label>

</div>

<div id="groupusers">
<h4>Users In Group</h4>

</div>

<div id="usersnotingroup">
<h4>Users Not In Group</h4>
</div>




</div>
<!-- END OF GROUP BLOCK-->
</form>



</div>
</div>
</div>

<div id="leftcolumn">
<div class="innertube">
<?php

 echo ($ADMINDISPLAY->display_main_admin_nav());
?>
</div>
</div>

<div id="footer"><p>&copy; OCS Group 2009</div>

</div>

<?php
$GENDISPLAY->body_close();
$GENDISPLAY->html_close();
?>

